﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sekretar.Repository;
using System.Linq;

namespace Sekretar
{
    public partial class OpstinaRecView : Common.Forms.RecView
    {
        ROpstina Opstina = new ROpstina();
        int id;
        public int ID;
        
        public OpstinaRecView(int id)
        {
            InitializeComponent();
            this.id = id;
        }

        private void OpstinaRecView_Load(object sender, EventArgs e)
        {
            if (id == 0)
                OpstinaBindingSource.DataSource = Opstina.Nov();
            else
                OpstinaBindingSource.DataSource = Opstina.Izmeni(this.id);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                OpstinaBindingSource.EndEdit();
                int i = Opstina.Snimi((DataLayer.Opstina)OpstinaBindingSource.Current);
                this.Index = Opstina.VratiSve().ToList().FindIndex(c => c.OpstinaId == i);
                this.ID = ((DataLayer.Opstina)OpstinaBindingSource.Current).OpstinaId;
            }
            catch (Exception ex)
            {
                Common.Tools.MessageError.Show(ex.Message);
                this.DialogResult = DialogResult.None;
            }
        }
    }
}
